import { createRouter,createWebHashHistory } from "vue-router";
import Home from "../components/Home.vue"
import Login from "../components/Login.vue"


let router=createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:"/home",
            component:Home
        },
        {
            path:"/login",
            component:Login
        },
        //默认去登录页面
        {
            path:"/",
            redirect:"/login"
        },
    ]
})


//前置路由守卫
router.beforeEach((to,from,next)=>{
    //你想去的页面是登录就放行
    if(to.path=="/login"){
        next();
    }else{
        //判断信息
        let username = localStorage.getItem("username");
        alert(username);
        if(username!='' && username!=null){
            alert("判断通过")
            next();
        }else{
            alert("去login页面")
            next("/login");
        }
    }
})



export default router;